package com.example.tourpal.model;

import java.io.File;

import android.content.Context;

public class LocalDataLoaderHelp {
	public static final String BASE_IP_URL = "http://121.40.133.222:8080";// http://222.73.205.208:8080
	public static final String DATA_API_URL = BASE_IP_URL
			+ "/lyb/api/v1/plan/viewIndex/";
	public static final String ADD_DATA_API_URL = BASE_IP_URL
			+ "/lyb/api/v1/plan/ak/addComment/";
	public static final String PUBLISH_JOURNEY_URL = BASE_IP_URL
			+ "/lyb/api/v1/plan/ak/addJourney";
	public static final String DATA_JOURNEY_API_URL = BASE_IP_URL
			+ "/lyb/api/v1/plan/viewJourney/";
	public static final String DATA_COMMENT_VIEW = BASE_IP_URL
			+ "/lyb/api/v1/plan/viewPlanComment/";
	public static final String DATA_ADD_PRAISE_URL = BASE_IP_URL
			+ "/lyb/api/v1/plan/ak/addPraiseNum/";
	public static final String DATA_DELETE_COMMENT_URL = BASE_IP_URL
			+ "/lyb/api/v1/plan/ak/delPlanComment/";
	public static final String DATA_DELETE_JOURNEY_URL = BASE_IP_URL
			+ "/lyb/api/v1/plan/ak/delJourney/";
	public static final String DATA_DELETE_PLAN_URL = BASE_IP_URL
			+ "/lyb/api/v1/plan/ak/delPlan/";
	public static final String DATA_DELETE_JOURNEY_TYPE_URL = BASE_IP_URL
			+ "/lyb/api/v1/plan/ak/delPlanNode/";
	// public static final String DATA_VIEW_USER_COLLECTION_URL =
	// "http://222.73.205.208:8080/lyb/api/v1/plan/ak/viewCollection/";//userid
	// public static final String DATA_ADD_USER_COLLECTION_URL =
	// "http://222.73.205.208:8080/lyb/api/v1/plan/ak/collection/";//userid/journeyid
	public static final String DATA_ADD_USER_COLLECTION_URL = BASE_IP_URL
			+ "/lyb/api/v1/plan/ak/autoAddJourney/";// userid/journeyid
	public static final String DATA_VIEW_USER_JOURNEY_URL = BASE_IP_URL
			+ "/lyb/api/v1/plan/viewJourneys/";// userid
	public static final String DATA_VIEW_USER_ALL_MESSAGE_URL = BASE_IP_URL
			+ "/lyb/api/v1/letter/getAllLetter/";// {page}?token=xxxxx
	public static final String DATA_VIEW_USER_TO_USER_MESSAGE_URL = BASE_IP_URL
			+ "/lyb/api/v1/letter/getLetter/";// {toUserId}/{page}?token=xxxxx
	public static final String DATA_DELETE_USER_TO_USER_MESSAGE_URL = BASE_IP_URL
			+ "/lyb/api/v1/letter/deleteLetter/";// {toUserId}?token=xxxxx
	public static final String DATA_DELETE_ONE_MESSAGE_URL = BASE_IP_URL
			+ "/lyb/api/v1/letter/deleteLetterById/";// {id}?token=xxxxx
	public static final String DATA_INSERT_ONE_MESSAGE_URL = BASE_IP_URL
			+ "/lyb/api/v1/letter/insertLetter/";// {toUserId}?token=xxxxx&content=kkkkkkk"
	public static final String DATA_QUERY_PLACE_URL = BASE_IP_URL
			+ "/lyb/api/v1/place/ak/viewPlace/";// place
	public static final int SQUARE_START_ACTION = 0x123;
	public static final int SQUARE_DONE_ACTION = 0x124;
	public static final int JOURNEY_START_ACTION = 0x125;
	public static final int JOURNEY_DONE_ACTION = 0x126;
	public static final int COMMENT_START_ACTION = 0x127;
	public static final int COMMENT_DONE_ACTION = 0x128;
	public static final int PUBLISH_JOURNEY_START_ACTION = 0x129;
	public static final int PUBLISH_JOURNEY_DONE_ACTION = 0x130;
	public static final int PUBLISH_COMMENT_START_ACTION = 0x131;
	public static final int PUBLISH_COMMENT_DONE_ACTION = 0x132;
	public static final int PUBLISH_ERROR_ACTION = 0x133;
	public static final int PUBLISH_COMMENT_ERROR = 0x134;
	public static final int VIEW_USER_JOURNEY_DONE_ACTION = 0x135;
	public static final int PUBLISH_USER_COLLECTION_DONE_ACTION = 0x136;
	public static final int PUBLISH_USER_COLLECTION_ERROR_ACTION = 0x137;
	public static final int DATA_VIEW_MESSAGE_DONE_ACTION = 0X138;
	public static final int DATA_QUERY_PLACE_DONE_ACTION = 0X139;
	public static final int DELETE_MESSAGE_SUCCESS_DONE_ACTION = 0X140;
	public static final int DELETE_MESSAGE_ERROR_DONE_ACTION = 0X141;
	public static final int SEND_MESSAGE_SUCCESS_DONE_ACTION = 0X142;
	public static final int SEND_MESSAGE_ERROR_DONE_ACTION = 0X143;
	public static final int SENDING_MESSAGE_ACTION = 0X144;
	public static final int NETWORK_ERROR_ACTION = 0x150;
	public static final int DOWNLOAD_ERROR_ACTION = 0x100;
	public static final String SQUARE_CACHE_NAME = "Persons";
	public static final String USER_JOURNEY_CACHE_NAME = "MyJourneys";
	public static final String USER_COLLECTION_CACHE_NAME = "MyCollections";
	public static final String JOURNEY_CACHE_NAME = "Journeys";
	public static final String COMMENT_CACHE_NAME = "Comments";
	public static final boolean TIME_EASY_FLAG = true;

	// delete data/data/com.example.tourpal/cache/
	public static void clearAppCache(final Context context) {
		new Thread() {
			public void run() {
				try {
					clearCacheFolder(context.getCacheDir(),
							System.currentTimeMillis());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}.start();
	}

	private static int clearCacheFolder(File dir, long curTime) {
		int deletedFiles = 0;
		if (dir != null && dir.isDirectory()) {
			try {
				for (File child : dir.listFiles()) {
					if (child.isDirectory()) {
						deletedFiles += clearCacheFolder(child, curTime);
					}
					if (child.lastModified() < curTime) {
						if (child.delete()) {
							deletedFiles++;
						}
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return deletedFiles;
	}

	public static String shortTime(String time) {
		try {
			if (time != null && LocalDataLoaderHelp.TIME_EASY_FLAG) {
				String[] str = time.split(" ");
				time = str[0].replace("-", "");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return time;
	}
}
